home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / uberwidgets / keycatcher.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  69 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from wx import NewId
  6. from collections import defaultdict
  7. from util import Delegate, memoize, funcinfo
  8. from gui.toolbox import keycodes
  9. _ids = set()
  10.  
  11. def MyNewId():
  12.     return None if not len(_ids) else _ids.pop()
  13.  
  14.  
  15. def ReleaseIds(ids):
  16.     _ids.update(ids)
  17.  
  18.  
  19. class KeyCatcher(wx.EvtHandler):
  20.     
  21.     def __init__(self, frame):
  22.         frame.Bind(wx.EVT_MENU, self._oncommandevent)
  23.         self.frame = frame
  24.         self.cbs = defaultdict((lambda : Delegate(ignore_exceptions = wx.PyDeadObjectError)))
  25.         self.idcbs = { }
  26.  
  27.     
  28.     def OnDown(self, shortcut, callback):
  29.         sc = str(shortcut)
  30.         accel = keycodes(sc, accel = True)
  31.         self.cbs[accel].insert(0, callback)
  32.         self.update_table()
  33.         
  34.         def rem(accel = accel, callback = callback, shortcut = (sc,)):
  35.             self.cbs[accel].remove(callback)
  36.  
  37.         return rem
  38.  
  39.     
  40.     def update_table(self):
  41.         idcbs = self.idcbs
  42.         ReleaseIds(idcbs.keys())
  43.         idcbs.clear()
  44.         entries = []
  45.         for modifiers, key in self.cbs.iteritems():
  46.             callback = None
  47.             wxid = MyNewId()
  48.             idcbs[wxid] = callback
  49.             entries.append((modifiers, key, wxid))
  50.         
  51.         atable = wx.AcceleratorTableFromSequence(entries)
  52.         if not atable.IsOk():
  53.             print 'warning: accelerator table is not OK'
  54.         
  55.         self.frame.SetAcceleratorTable(atable)
  56.  
  57.     
  58.     def _oncommandevent(self, e):
  59.         
  60.         try:
  61.             cbs = self.idcbs[e.Id]
  62.         except KeyError:
  63.             e.Skip()
  64.  
  65.         cbs(e)
  66.         e.Skip()
  67.  
  68.  
  69.